var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    // tab切换  
    currentTab: 1,
    re_pay: false,
    objarr: [],
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    height: 0,
    user_status: 'n',
    cats: [],
    nomore: true,
    jfen: 0,
    showDialog: false,
  },
  onLoad: function () {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight })
      }
    })

  },
  onShow() {
    this.getData();
  },
  getData() {
    this.setData({
      page: 1,
    })
    let par = {
      rd_session: app.globalData.userInfo.rd_session,
      page: this.data.page,
      page_size: this.data.pagesize
    }
    $.httpPost("good_list_jifen", par, (data, err) => {
      this.setData({
        objarr: data.data.lists,
        totalpage: data.data.total_page,
        jfen: data.total_point
      })
    })
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        page: this.data.page,
        page_size: this.data.pagesize
      }
      $.httpPost("good_list_jifen", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.lists) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },
  togz() {
    wx.navigateTo({
      url: '/pages/integral/gz',
    })
  },
  todetail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goods/goods_detail_jifen?id=' + id ,
    })
  },
  
  todh: function (e) {
    let id = e.currentTarget.dataset.id
    let num = e.currentTarget.dataset.num
    this.setData({
      showDialog: true,
      num: num,
      good_id: id
    })

  },
  checkinfo(name, phone, addr) {
    if (app.check_empty(name) || app.check_empty(phone) || app.check_empty(addr)) {
      wx.showToast({
        title: '不能是空',
      })
      return false
    } else {
      if (app.checkPhone(phone)) {
        return true
      } else {
        wx.showToast({
          title: '手机格式不正确',
        })
        return false
      }

    }
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    let name = e.detail.value.username
    let phone = e.detail.value.userphone
    let addr = e.detail.value.addr
    if (this.checkinfo(name, phone, addr)) {
      let params = {
        rd_session: app.globalData.userInfo.rd_session,
        good_id: this.data.good_id,
        name: name,
        phone: phone,
        address: addr
      }
      $.httpPost("get_good_jifen", params, (data, err) => {
        this.setData({
          showDialog: false
        })
        wx.showToast({
          title: data.message,
          duration: 2000,
        })
        if (data.result == 'success') {

        }
      })
    }
  },

  formReset: function () {
    this.setData({
      showDialog: false
    })
  }
})  